﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web;
namespace OneShoppingUtility
{
    public class UtilityString
    {
       
        /// <summary>
        /// 将字符c分割开的字符串当中的重复值删除
        /// </summary>
        /// <param name="str">需要处理的字符串</param>
        ///  <param name="str">分割字符</param>
        /// <returns>使用字符c分割开的不包含重复值的字符串</returns>
        public static string DelStr(string str, char c)
        {

            ArrayList al = new ArrayList();
            string[] arr = str.Split(c);//拆分后的字符数组   

            for (int i = 0; i < arr.Length; i++)
            {
                if (al.Contains(arr[i]) == false)//判断 要拆分的字符串 中是否已经存在于这个ArrayList中   
                {
                    al.Add(arr[i]);//不存在则添加进ArrayList   
                }
            }
            return String.Join(c.ToString(), (string[])al.ToArray(typeof(string)));//把ArrayList里的数组值组合成一个字符串 
        }
        /// <summary>
        /// 提取字符c分割开的字符串1和字符串2当中的重复值
        /// </summary>
        /// <param name="str1">字符串1</param>
        /// <param name="str2">字符串2</param>
        /// <param name="c">分割字符</param>
        /// <returns>字符串1和字符串2中重复值字符串</returns>
        public static string PublicStr(string str1,string str2, char c)
        {

            ArrayList al = new ArrayList();
            string[] arr1 = str1.Split(c);
            string[] arr2 = str2.Split(c);
            for (int i = 0; i < arr1.Length; i++)
            {
                if (arr2.Contains(arr1[i]) == true)
                {
                    al.Add(arr1[i]);//存在则添加进ArrayList   
                }
            }
            return String.Join(c.ToString(), (string[])al.ToArray(typeof(string)));//把ArrayList里的数组值组合成一个字符串 
        }
    }

    public static class StringHelper
    {
        /// <summary>
        /// 字符串是否为空
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsEmptyString(this string str)
        {
            if (string.IsNullOrEmpty(str)|| str.Length == 0) return true;
            else return false;
        }


        /// <summary>
        /// 防止输入SQL注入
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string CleanSQL(this string str)
        {
            if (str == null || str == "")
                return string.Empty;
            str = str.Trim();
            str = str.Replace(";", "");
            str = str.Replace("'", "");
            str = str.Replace("&", "");
            str = str.Replace("%20", "");
            str = str.Replace("--", "");
            str = str.Replace("==", "");
            str = str.Replace("<", "");
            str = str.Replace(">", "");
            str = str.Replace("%", "");
            str = str.Replace("+", "");
            str = str.Replace("-", "");
            str = str.Replace("=", "");
            str = str.Replace(",", "");
            return str;
        }
    }




}